package com.itheima.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.PageInfo;
import com.itheima.domain.User;
import com.itheima.service.UserService;
import org.apache.ibatis.jdbc.Null;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class UserController {
    @Autowired
    private UserService userService;
    @RequestMapping(value = "/get",method = RequestMethod.POST)
    @ResponseBody
    public User get(@RequestBody Integer id){
        User user = userService.get(id);


        return user;

    }


@RequestMapping("/update")
@ResponseBody
    public boolean update(@RequestBody  User user){

    boolean update = userService.update(user);
    return update;
}

    @RequestMapping("/save")
    @ResponseBody
    public boolean save(@RequestBody  User user){

        boolean res = userService.save(user);
        return res;
    }
    @RequestMapping("/delete")
    @ResponseBody
    public boolean delete(@RequestBody  Integer id){


        boolean res = userService.delete(id);
        return res;
    }
    @RequestMapping("/getAll")
    @ResponseBody
    public PageInfo<User> getAll(Integer page,Integer size){

        System.out.println(page);
        System.out.println(size);
        PageInfo<User> all = userService.getAll(page, size);
        return all;
    }
    @RequestMapping("/login")
    @ResponseBody
    public User getByUserNameAndPassword(String userName,String password){

        User byUserNameAndPassword = userService.getByUserNameAndPassword(userName, password);
        return byUserNameAndPassword;
    }
}
